Skip to content

fix: keep global security defaults scoped#32

Merged
roderik merged 1 commit intomainfrom
fix/security-contexts-inheritance
Sep 18, 2025
Merged

fix: keep global security defaults scoped#32
roderik merged 1 commit intomainfrom
fix/security-contexts-inheritance

Conversation

@roderik
Copy link
Copy Markdown
Member

@roderik roderik commented Sep 18, 2025

Summary

  • resolve global security context defaults into a temporary map instead of emitting raw YAML
  • merge pod/container contexts with set-based helper to avoid leaking other global values into securityContext blocks
  • update Besu and bootstrapper manifests to consume the shared helper without fromYaml conversions

Testing

  • helm template test charts/network --namespace test
  • bun run check
  • bun run typecheck
  • bun run test

Summary by Sourcery

Refactor Helm chart security context helpers to isolate global defaults in a scoped map and update chart templates to use the new helper signature, eliminating raw YAML emission and parsing.

Bug Fixes:

  • Prevent leaking unrelated global securityContext values into pod and container contexts

Enhancements:

  • Refactor securityContexts helper to accept a destination map and merge global pod/container defaults with chart overrides in-place
  • Update network-bootstrapper and network-nodes templates to initialize a dest dict and invoke the refactored helper without relying on raw YAML or fromYaml parsing

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @roderik, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the handling of security contexts within Helm charts to ensure global defaults are applied precisely and without unintended side effects. By modifying helper templates to directly populate security context dictionaries and updating consuming manifests to leverage this new approach, the change streamlines the configuration process and enhances the isolation of security settings, preventing 'leaking' of global values.

Highlights

  • Refactored Security Context Helper: The securityContexts helper templates (network-bootstrapper.securityContexts and nodes.securityContexts) no longer emit raw YAML. Instead, they directly populate a provided dictionary with resolved pod and container security contexts, improving control over the merging process.
  • Eliminated YAML Conversions: Manifests such as job.yaml, statefulset-rpc.yaml, and statefulset-validator.yaml now directly receive the security contexts as a dictionary from the helper, removing the need for toYaml | fromYaml serialization and deserialization steps.
  • Improved Scoping of Global Defaults: This change prevents potential issues where global security context defaults could inadvertently affect other parts of the manifest due to previous YAML conversion processes, ensuring they are correctly scoped to podSecurityContext and containerSecurityContext blocks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the qa:running QA workflow is currently running label Sep 18, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Sep 18, 2025

To view in Slack, search for: 1758207815.129239

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions github-actions Bot added the status:ready-for-review Pull request is ready for review label Sep 18, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the security context helpers in the Helm charts to avoid using the toYaml | fromYaml pattern. The new approach, which involves passing a dictionary to be populated by the helper, is a great improvement that aligns with modern Helm best practices, enhancing maintainability and robustness. The changes are well-implemented across the affected templates. I've added a couple of minor suggestions to use the dig function for a more concise implementation when accessing nested values, but overall this is a solid improvement.

Comment on lines +88 to +90
{{- $globalSecurityContexts := default (dict) (get $globalValues "securityContexts") -}}
{{- $podDefaults := default (dict) (get $globalSecurityContexts "pod") -}}
{{- $containerDefaults := default (dict) (get $globalSecurityContexts "container") -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the use of get and default is correct, you could use the dig function to make this code more concise. The dig function is designed for safely accessing potentially missing keys in nested maps, which is exactly what's being done here. This would also make the implementation more consistent with the previous version of the code.

{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) -}}
{{- $podDefaults := dig "pod" $globalSecurityContexts (dict) -}}
{{- $containerDefaults := dig "container" $globalSecurityContexts (dict) -}}

Comment on lines +137 to +139
{{- $globalSecurityContexts := default (dict) (get $globalValues "securityContexts") -}}
{{- $podDefaults := default (dict) (get $globalSecurityContexts "pod") -}}
{{- $containerDefaults := default (dict) (get $globalSecurityContexts "container") -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For conciseness and consistency, consider using the dig function here. It's well-suited for safely accessing nested map keys and would make the code more compact, similar to the previous implementation.

{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) -}}
{{- $podDefaults := dig "pod" $globalSecurityContexts (dict) -}}
{{- $containerDefaults := dig "container" $globalSecurityContexts (dict) -}}

@github-actions github-actions Bot added qa:success QA workflow passed successfully fix Bug fix and removed qa:running QA workflow is currently running labels Sep 18, 2025
@roderik roderik merged commit 840023a into main Sep 18, 2025
16 checks passed
@roderik roderik deleted the fix/security-contexts-inheritance branch September 18, 2025 15:06
@github-actions github-actions Bot added status:merged Pull request has been merged and removed status:ready-for-review Pull request is ready for review labels Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix qa:success QA workflow passed successfully status:merged Pull request has been merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant